class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        count = dict()
        for i in range(len(nums)):
            # print(count.keys())
            if nums[i] not in count.keys():
                count[nums[i]] = 1
            else:
                count[nums[i]] += 1
        for key, value in count.items():
            if value > len(nums)//2:
                return key



class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        count, candidate = 0, None
        # 用count计数，最多的那个一定会是count最后保留的值
        for num in nums:
            if count == 0:
                candidate = num
            count = count + 1 if num == candidate else count - 1
        return candidate


test = Solution()
print(test.majorityElement([3,2,3]))